home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
satellit
/
orbits
/
passupdt
/
passupdt.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-09-13
|
16KB
|
520 lines
{$M 15520,0,0}
Program Pass_Update_2;
{ Author: Dr TS Kelso }
{ Original Version: 1989 Nov 04 }
{ Current Revision: 1992 Sep 13 }
{ Version: 2.50 }
{ Copyright: 1989-1992, All Rights Reserved }
{ Program Purpose: Automatically updates two-line element set files. }
{$N+}
Uses CRT,DOS,MinMax,SGP_Init,SGP_In,SGP_Time,Support;
const
tle_files = 49;
type
satnr = string[5];
filename = string;
var
ask_to_update,ask_to_delete_old,
ask_to_delete_missing : boolean;
choice : char;
lines,pause : word;
nr_files,position,old_position,
index,delta,counter : integer;
today : double;
default_drive,old_elset,new_elset : string[3];
old_satnr,new_satnr,sat_nr,obj_nr : satnr;
satname : string[25];
old_epoch,new_epoch : string[14];
outfilename,
update_filename,default_directory : filename;
old_line,line : two_line;
tle_input,oldfile,tle_output,archive : text;
selected : array [0..tle_files] of boolean;
tle_file : array [0..tle_files] of filename;
dirinfo : SearchRec;
Procedure Initialize;
var
key : char;
update_file : filename;
buffer : string[80];
infile : text;
begin
NormalVideo;
ClrScr;
Cursor_Off;
Writeln('╔════════════════════════╗');
Writeln('║ Two-Line Element Set ║');
Writeln('║ Update ║');
Writeln('╠════════════════════════╣');
Writeln('║ Written by ║');
Writeln('║ TS Kelso ║');
Writeln('║ ║');
Writeln('║ Copyright 1989-1992 ║');
Writeln('║ All Rights ║');
Writeln('║ Reserved ║');
Writeln('╠════════════════════════╣');
Writeln('║ Version 2.50 ║');
Writeln('║ 1992 Sep 13 ║');
Writeln('╚════════════════════════╝');
Writeln;
Writeln('This program will allow the user to automatically update all two-line element');
Writeln('set files (.TLE) in the default directory. Within each file being updated,');
Writeln('element sets with a more recent epoch and element set number are automatic-');
Writeln('ally updated. Otherwise, the user is queried as to whether an update should');
Writeln('be made. The configuration can be set to bypass these queries. The user also');
Writeln('has the option of updating archives of individual satellites from the master');
Writeln('file by specifying these satellites in a separate data file.');
Assign(infile,'PASSUPDT.CFG');
{$i-} Reset(infile); {$i+}
if IOResult <> 0 then
Report_Error(41,1,'File PASSUPDT.CFG missing!');
Readln(infile,default_drive);
if Pos(' ',default_drive) <> 0 then
default_drive := Copy(default_drive,1,Pos(' ',default_drive)-1);
Readln(infile,default_directory);
if Pos(' ',default_directory) <> 0 then
default_directory := Copy(default_directory,1,Pos(' ',default_directory)-1);
Readln(infile,update_file);
if Pos(' ',update_file) <> 0 then
update_file := Copy(update_file,1,Pos(' ',update_file)-1);
update_filename := update_file;
if Pos(':',update_filename) <> 0 then
Delete(update_filename,1,2);
if Pos('\',update_file) = 0 then
update_file := default_directory + update_file
else
while Pos('\',update_filename) <> 0 do
Delete(update_filename,1,Pos('\',update_filename));
if Pos(':',update_file) = 0 then
update_file := default_drive + update_file;
Readln(infile,pause);
Readln(infile,choice);
if Upcase(choice) = 'Y' then
ask_to_update := true
else
ask_to_update := false;
Readln(infile,choice);
if Upcase(choice) = 'Y' then
ask_to_delete_old := true
else
ask_to_delete_old := false;
Readln(infile,choice);
if Upcase(choice) = 'Y' then
ask_to_delete_missing := true
else
ask_to_delete_missing := false;
Readln(infile,lines);
if not (lines in [2,3]) then
lines := 3;
Close(infile);
Assign(tle_input,update_file);
{$i-} Reset(tle_input); {$i+}
if IOResult <> 0 then
Report_Error(41,1,'Master update file not found!');
counter := 0;
repeat
counter := counter + 1;
Readln(tle_input,buffer);
until Copy(buffer,1,2) = '1 ';
if lines = 3 then
counter := counter - 2
else
counter := counter - 1;
GotoXY(1,24);
Write('<Press any key to continue>');
repeat until keypressed;
key := ReadKey;
end; {Procedure Initialize}
Procedure Deinitialize;
begin
GotoXY(1,24);
ClrEOL;
NormalVideo;
Write('<Processing complete>');
Cursor_On;
end; {Procedure Deinitialize}
Procedure Epoch(var day : double);
var
yr,mo,dy,wd : word;
begin
GetDate(yr,mo,dy,wd);
day := Julian_Date_of_Year(yr) + DOY(yr,mo,dy);
end; {Procedure Epoch}
Function Set_Color(Line_1 : line_data) : word;
var
i : integer;
edate : double;
begin
edate := Julian_Date_of_Epoch(Real_Value(line_1,19,14));
delta := Round(today - edate);
if delta < 0 then
Set_Color := LightBlue
else
case delta of
0..15 : Set_Color := LightGreen;
16..30 : Set_Color := Yellow;
31..45 : Set_Color := LightRed;
else
Set_Color := Brown;
end; {case}
end; {Function Set_Color}
Procedure Update_TLEs(TLE_filename : filename);
const
screen_pos = 15;
var
update,skip : boolean;
i : integer;
checkfile : text;
begin
skip := false;
for i := screen_pos to screen_pos + 9 do
begin
GotoXY(1,i);
ClrEOL;
end; {for i}
GotoXY(1,screen_pos);
TextColor(LightGray);
Write('Updating ',TLE_filename,'...');
Delay(pause);
Reset(tle_input);
for i := 1 to counter do
Readln(tle_input);
TLE_filename := Copy(TLE_filename,1,Pos('.',TLE_filename)-1);
Assign(checkfile,default_drive + default_directory + TLE_filename + '.BAK');
{$i-} Reset(checkfile); {$i+}
if IOResult = 0 then
begin
Close(checkfile);
Erase(checkfile);
end; {if}
Assign(oldfile,default_drive + default_directory + TLE_filename+'.TLE');
Rename(oldfile,default_drive + default_directory + TLE_filename+'.BAK');
Reset(oldfile);
Assign(tle_output,default_drive + default_directory + TLE_filename+'.TLE');
Rewrite(tle_output);
repeat
Readln(oldfile,satname);
Readln(oldfile,old_line[1]);
Readln(oldfile,old_line[2]);
GotoXY(1,screen_pos+2);
TextColor(White);
Writeln(satname);
TextColor(Set_Color(old_line[1]));
Writeln(old_line[1]);
Writeln(old_line[2]);
Writeln;
GotoXY(1,screen_pos+6); ClrEOL;
GotoXY(1,screen_pos+7); ClrEOL;
GotoXY(1,screen_pos+8); ClrEOL;
GotoXY(1,screen_pos+9); ClrEOL;
old_satnr := Copy(old_line[1],3,5);
old_epoch := Copy(old_line[1],19,14);
old_elset := Copy(old_line[1],66,3);
repeat
TextColor(LightGray);
if not skip then
begin
if lines = 3 then
Readln(tle_input);
Readln(tle_input,line[1]);
Readln(tle_input,line[2]);
new_satnr := Copy(line[1],3,5);
end; {if}
skip := false;
GotoXY(3,screen_pos+6);
Write(new_satnr);
until (new_satnr >= old_satnr) or EOF(tle_input);
if new_satnr <> old_satnr then
begin
GotoXY(1,screen_pos+6);
TextColor(LightRed);
Write('New data not found. Delete? ');
Buzz;
if ask_to_delete_missing then
update := not yes
else
begin
update := true;
Write('No');
Delay(pause);
end; {else}
if update then
begin
Writeln(tle_output,satname);
Writeln(tle_output,old_line[1]);
Writeln(tle_output,old_line[2]);
end;
skip := true;
end {if}
else
begin
GotoXY(1,screen_pos+6);
TextColor(Set_Color(line[1]));
Writeln(line[1]);
Writeln(line[2]);
Writeln;
if Good_Elements(line) then
begin
new_epoch := Copy(line[1],19,14);
new_elset := Copy(line[1],66,3);
if (new_epoch >= old_epoch) and
(new_elset > old_elset) then
begin
TextColor(LightGreen);
Write('Writing updated element set...');
Writeln(tle_output,satname);
Writeln(tle_output,line[1]);
Writeln(tle_output,line[2]);
end {if}
else
if (new_epoch = old_epoch) and
(new_elset = old_elset) then
begin
TextColor(Yellow);
Write('No change...');
if delta > 30 then
begin
Write(' Delete? ');
Buzz;
if ask_to_delete_old then
update := not yes
else
begin
update := true;
Write('No');
Delay(pause);
end; {else}
end {if}
else
update := true;
if update then
begin
Writeln(tle_output,satname);
Writeln(tle_output,old_line[1]);
Writeln(tle_output,old_line[2]);
end; {if}
end {if}
else
begin
Write('Replace? ');
Buzz;
if ask_to_update then
update := yes
else
if new_epoch > old_epoch then
begin
update := true;
Write('Yes');
Delay(pause);
end {else if}
else
begin
update := false;
Write('No');
Delay(pause);
end; {else else}
if update then
begin
Writeln(tle_output,satname);
Writeln(tle_output,line[1]);
Writeln(tle_output,line[2]);
end {if replace}
else
begin
Writeln(tle_output,satname);
Writeln(tle_output,old_line[1]);
Writeln(tle_output,old_line[2]);
end; {else}
end; {else}
end {if}
else
begin
TextColor(LightRed);
Writeln('Checksum(s) bad!');
Buzz; Buzz;
Writeln(tle_output,satname);
Writeln(tle_output,old_line[1]);
Writeln(tle_output,old_line[2]);
Delay(pause);
end; {else}
end; {else}
Delay(pause);
until EOF(oldfile);
Close(tle_input);
Close(oldfile);
Close(tle_output);
end; {Procedure Update_TLEs}
Procedure Show(index : byte);
begin
GotoXY(16*(index mod 5) + 1,(index div 5) + 3);
if index = position then
TextBackground(blue)
else
TextBackground(black);
if selected[index] then
TextColor(yellow)
else
TextColor(lightgray);
Write(Copy(' '+TLE_file[index]+' ',1,14));
TextBackground(black);
end; {Procedure Show}
BEGIN
Initialize;
Epoch(today);
FindFirst(default_drive+default_directory+'*.TLE',AnyFile,dirinfo);
If DOSError <> 0 then
Report_Error(41,1,'No *.TLE files found!');
ClrScr;
HighVideo;
Write('Select files to update:');
NormVideo;
Show_Status_Line('[A to toggle all, Cursor to position, <SPACE> to toggle, <CR> when done]');
index := -1;
position := 0;
while DOSError = 0 do
begin
index := index + 1;
TLE_file[index] := dirinfo.name;
selected[index] := false;
Show(index);
FindNext(dirinfo);
end; {while}
nr_files := index;
repeat
choice := Upcase(ReadKey);
case choice of
'A' : begin
for index := 0 to nr_files do
begin
selected[index] := not selected[index];
Show(index);
end; {for index}
end; {Toggle All}
'U' : begin
for index := 0 to nr_files do
begin
selected[index] := false;
Show(index);
end; {for index}
end; {Untag All}
' ' : begin
selected[position] := not selected[position];
old_position := position;
position := IMin(position + 1,nr_files);
Show(old_position);
Show(position);
end; {Toggle}
#00 : begin
choice := ReadKey;
old_position := position;
case choice of
Home : position := 0;
Up : position := IMax(position - 5,0);
Dn : position := IMin(position + 5,nr_files);
Lt : position := IMax(position - 1,0);
Rt : position := IMin(position + 1,nr_files);
Endd : position := nr_files;
end; {case}
Show(old_position);
Show(position);
end; {Cursor positioning}
end; {case}
until choice = CR;
old_position := position;
GotoXY(1,25);
ClrEOL;
for index := 0 to nr_files do
if selected[index] and (tle_file[index] <> update_filename) then
begin
position := index;
Show(index);
Show(old_position);
GotoXY(1,1);
Update_TLEs(TLE_file[index]);
selected[index] := false;
old_position := position;
position := -1;
Show(index);
if keypressed then
if ReadKey = ESC then
Report_Error(41,1,'Processing interrupted...');
end; {if}
{ Update database files -- Dyy }
Assign(archive,'PASSUPDT.CAT');
{$i-} Reset(archive); {$i+}
if IOResult = 0 then
begin
ClrScr;
Writeln('Updating archive files...');
Write('['); TextColor(lightgreen);
Write('Green'); TextColor(lightgray);
Writeln(' = Updated]');
Writeln;
Reset(tle_input);
for index := 1 to counter do
Readln(tle_input);
Readln(archive,sat_nr);
repeat
if lines = 3 then
Readln(tle_input);
Readln(tle_input,line[1]);
Readln(tle_input,line[2]);
obj_nr := Copy(line[1],3,5);
Write(obj_nr:8,^H^H^H^H^H^H^H^H);
if obj_nr >= sat_nr then
begin
if obj_nr = sat_nr then
begin
outfilename := 'SAT'+sat_nr+'.D'+Copy(line[1],19,2);
Assign(tle_output,default_drive + default_directory + outfilename);
{$i-} Reset(tle_output); {$i+}
if IOResult = 0 then
begin
repeat
Readln(tle_output,old_line[1]);
Readln(tle_output,old_line[2]);
until EOF(tle_output);
if (old_line[1] <> line[1]) or (old_line[2] <> line[2]) then
begin
Append(tle_output);
TextColor(lightgreen);
Write(sat_nr:8);
TextColor(lightgray);
Writeln(tle_output,line[1]);
Writeln(tle_output,line[2]);
end {if}
else
Write(sat_nr:8);
end {if}
else
begin
Rewrite(tle_output);
TextColor(lightgreen);
Write(sat_nr:8);
TextColor(lightgray);
Writeln(tle_output,line[1]);
Writeln(tle_output,line[2]);
end; {else}
Close(tle_output);
end; {if}
if not EOF(archive) then
Readln(archive,sat_nr);
end; {if}
until EOF(tle_input);
ClrEOL;
end; {if}
DeInitialize;
END.